<?php
defined('BASEPATH') OR exit('No direct script access allowed');

class Th_model extends CI_Model {

	//取全部教师
	public function getall(){
		$res = $this->db->get('teacher');
		return $res;
	}

	//取某个教师
	public function getone($id){
		$res = $this->db->get_where('teacher',array('id'=>$id));
		return $res->row();
	}

	//根据id取教师姓名
	public function getname($id){
		$this->db->select('name');
		$res = $this->db->get_where('teacher',array('id'=>$id));
		return $res->row();
	}

	//删除教师
	public function delete($id){
		$bool = $this->db->delete('teacher',array('id'=>$id));
		return $bool;
	}

	//添加教师
	public function insert($i){
		$data = array(
			'name'=>$i['name'],
			'password'=>md5($i['password']),
			'tel'=>$i['tel'],
			'email'=>$i['email'],
			'bumen'=>$i['bumen']
		);
		//$this->db->set($data);
		$bool = $this->db->insert('teacher',$data);
		return $bool;
	}

	//更新教师
	public function updata($i){
		$data = array(
			'id'=>$i['id'],
			'name'=>$i['name'],
			'password'=>md5($i['password']),
			'tel'=>$i['tel'],
			'email'=>$i['email'],
			'bumen'=>$i['bumen']
		);
		$bool = $this->db->replace('teacher', $data);
		return $bool;
	}

	//根据账号取回教师
	public function ckth($name){
		$query = $this->db->get_where('teacher',array('name'=>$name));
		return $query->row();
	}

}